import os
import shutil

def reorganize_project():
    """重组项目结构，添加功能前缀"""
    
    # 功能模块映射
    module_prefixes = {
        "translation": "trans_",  # 翻译相关
        "chat": "chat_",         # 聊天相关
        "image": "img_",         # 图像相关
        "voice": "voice_",       # 语音相关
        "text": "text_",         # 文本处理相关
        "base": "base_",         # 基础功能
        "utils": "util_",        # 工具类
        "services": "svc_",      # 服务类
        "tests": "test_"         # 测试相关
    }
    
    # 文件重命名映射
    file_renames = {
        # 翻译模块
        "modules/translation/translator.py": "modules/translation/trans_model.py",
        "modules/translation/language_detector.py": "modules/translation/trans_lang_detector.py",
        
        # 聊天模块
        "modules/chat/chat_model.py": "modules/chat/chat_core.py",
        "modules/chat/memory.py": "modules/chat/chat_memory.py",
        
        # 工具类
        "utils/logger.py": "utils/util_logger.py",
        "utils/validators.py": "utils/util_validators.py",
        "utils/term_processor.py": "utils/util_term_processor.py",
        "utils/db_manager.py": "utils/util_db_manager.py",
        
        # 服务类
        "services/model_manager.py": "services/svc_model_manager.py",
        "services/term_translation_service.py": "services/svc_term_translation.py",
        
        # 测试文件
        "tests/unit/test_translation.py": "tests/unit/test_trans_model.py",
        "tests/unit/test_language_detector.py": "tests/unit/test_trans_detector.py",
        "test_language_and_translation.py": "test_trans_integration.py",
        "test_translation_debug.py": "test_trans_debug.py",
        
        # 数据库相关
        "create_tables.py": "db_create_tables.py",
        "update_database.py": "db_update_terms.py",
        "test_db_connection.py": "test_db_connection.py"
    }
    
    # 执行重命名
    for old_path, new_path in file_renames.items():
        if os.path.exists(old_path):
            # 确保目标目录存在
            os.makedirs(os.path.dirname(new_path), exist_ok=True)
            # 重命名文件
            shutil.move(old_path, new_path)
            print(f"Renamed: {old_path} -> {new_path}")
    
    print("\nProject structure reorganized successfully!")

if __name__ == "__main__":
    reorganize_project() 